package com.kalix.ynpetroleum.overview.biz;

import com.kalix.framework.core.util.ConfigUtil;
import com.kalix.ynpetroleum.overview.api.biz.IOverviewBeanService;
import com.kalix.ynpetroleum.overview.api.dao.IOverviewBeanDao;
import com.kalix.ynpetroleum.overview.api.model.HttpRequestUtil;
import com.kalix.ynpetroleum.overview.entities.OverviewBean;
import com.kalix.framework.core.impl.biz.GenericBizServiceImpl;
import org.json.JSONObject;


/**
 *@ Author  ZhaoHang
 * @Date  2019/11/27
 **/
public class OverviewBeanServiceImpl extends GenericBizServiceImpl<IOverviewBeanDao, OverviewBean> implements IOverviewBeanService {
    public String getEquipment() {
        String wsIp = (String) ConfigUtil.getConfigProp("FREEBOARD_IP","config.ynpetroleum.portconf");
        String wsPort =(String)ConfigUtil.getConfigProp("FREEBOARD_PORT","config.ynpetroleum.portconf");
        String data= HttpRequestUtil.getXpath("http://"+wsIp+":"+wsPort+"/om/statistics/overstep/summary");
        JSONObject jsonObject = new JSONObject(data);
        Object patrolcount =  jsonObject.get("patrolcount");// 自动巡查
        Object oversteprate =  jsonObject.get("oversteprate");// 智维越界比例
        Object diagnosiscount =  jsonObject.get("diagnosiscount");// 执行智能诊断
        Object totalmo =  jsonObject.get("totalmo");//  总对象数
        Object overstepcount =  jsonObject.get("overstepcount");// 智维越界

        JSONObject json = new JSONObject(HttpRequestUtil.getXpath("http://"+wsIp+"/reportengine/rest/reports/count/allCycle"));
        Object day =  json.get("1");// 新增日报表数
        Object week =  json.get("2");// 新增周报表数
        Object month =  json.get("3");// 新增月报表数
        Object objs =  json.get("6");// 新增其他报表数

        JSONObject  l= new JSONObject();
        l.put("0","其他新增报表");
        l.put("1","自动巡查");
        l.put("2","智能越界");
        l.put("3","智能越界比例");
        l.put("4","执行智能诊断");
        l.put("5","新增月报表");
        l.put("6","新增周报表");
        l.put("7","新增日报表");

        JSONObject  list= new JSONObject();
        list.put("0",objs);
        list.put("1",patrolcount);
        list.put("2",overstepcount);
        list.put("3",oversteprate);
        list.put("4",diagnosiscount);
        list.put("5",month);
        list.put("6",week);
        list.put("7",day);

        String str = "[";
        for(int i = 0; i < 8 ; i++ ) {
            if(i == 7) {
                str += "{'name':'"+l.get(""+i)+"\\n" + list.get(""+i)+"张',\n'value':"+totalmo+"}]";
            }else {
                str += "{'name':'"+l.get(""+i)+"\\n" + list.get(""+i)+"张',\n'value':"+totalmo+"},\n";
            }
        }
        return str;
    }
}
